#include<stdio.h>
#include<stdlib.h> 
void Merger2(int left1,int right1,int left2,int right2,int *a){
	int *temp=(int*)malloc(sizeof(int)*(right2-left1+1)) ;
	int i=left1;
	int j=left2;
	int m=0;
	int s;
	int g=0;
     while(i<=right1&&j<=right2){
     	if(a[i]<a[j]){
     		temp[m++]=a[i++];
     	}
     	else{
     		temp[m++]=a[j++];
     	}
     }
     while(i<=right1){
     	temp[m++]=a[i++];
     }while(j<=right2){
     	temp[m++]=a[j++];
     }
     for(int s=left1;s<=right2;s++){
     	a[s]=temp[g++];
     }
     free(temp);

	
}
void Merger1(int left,int right,int* a){
	int min;
	if(left==right)return;
	else{
		min=(left+right)/2;
		Merger1(left,min,a);
		Merger1(min+1,right,a);
		int left1=left;
		int right1=min;
		int left2=min+1;
		int right2=right;
		Merger2(left1,right1,left2,right2,a);
	}
} 
int main(){
	int a[10]={5,6,3,1,8,9,10,2,6,7};
	Merger1(0,9,a);
	for(int i=0;i<10;i++){
		printf("%d ",a[i]);
	}
}
